package com.example.service.impl.contractManage;

import com.example.entity.Contract;
import com.example.entity.ContractVO;
import com.example.entity.SysUser;
import com.example.mapper.contractManage.ContractRenewMapper;
import com.example.service.contractManage.ContractRenewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * ----MaxCV工程师---
 *
 * @author wangbiao
 * @date2024/12/7
 * @desc
 */
@Service
public class ContractRenewServiceImpl implements ContractRenewService {

    @Autowired
    private ContractRenewMapper contractRenewMapper;


    /**
     * 查询需要续签的合同
     */
    @Override
    public List<ContractVO> renewList(ContractVO contractVO) {
        return contractRenewMapper.renewList(contractVO);
    }


    /**
     * 不续签
     * @param contractId
     * @return
     */
    @Override
    public int unRenew(int contractId) {
        return contractRenewMapper.unRenew(contractId);
    }


    /**
     * 续签
     * @param contract
     * @return
     */
    @Override
    public Integer renew(Contract contract) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

        SysUser sysUser = (SysUser) request.getSession().getAttribute("sysUser");
        String userName = sysUser.getUserName();
        contract.setUpdateBy(userName);
        contract.setUpdateTime(new Date());
        contract.setContractState(1);
        return contractRenewMapper.renew(contract);
    }
}
